<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="model.WeiGui"%>
<%@ page import="dao.WeiGuiDao"%>
<%@ page import="java.util.List" %>

<%
	//检查会话中是否有 "sg" 属性
	Object fdyObj = session.getAttribute("sg");
	if (fdyObj == null) {
	    response.sendRedirect("../view/Login.jsp");
	    return;
	}
%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>宿管页面</title>
<link href="../css/Utils.css" rel="stylesheet" type="text/css" />
<link href="../css/List.css" rel="stylesheet" type="text/css" />
<!-- 违规功能列表 -->
<link rel="stylesheet" href="../css/WeiGuilist.css">
<!-- 退出登录专用 -->
   <script type="text/javascript" src="../view/Loginout.js"></script>
</head>
<body>

<!-- 头部 -->
<div class="header" ><br>
<nerong>&nbsp;&nbsp;宿管页面&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;</nerong>

 <button onclick="confirmLogout('<%= (String)session.getAttribute("sg") %>','sg')">退出登录</button>

</div><br>

<div class="left" >
<table width="80%" height="80%">
<th>
<nerong>宿管可选择内容</nerong>

</th>
<tr>
<td>
<a href="../View_Msg/msgSg.jsp">&emsp;个人信息</a><br>
</td>
</tr>

<tr>
<td>
<a href="../View_SuShe/SuSheSG_List.jsp">&emsp;楼栋学生信息查询</a><br>
</td>
</tr>
<tr>

<td>
<a href="../View_fix/SgFix.jsp">&emsp;公物报修</a><br>

</td>
</tr>

<tr>
<td>
<a href = "WeiGuiSG.jsp">&emsp;宿舍违规信息处理</a><br>
</td>
</tr>


</table>

</div>



<div class="context" >
<!-- 这部分是每个大功能的小功能 -->
 <h2>违规情况</h2>
		<table class="Alltable">
        <thead>
            <tr>
                <th>学号</th>
                <th>时间</th>
                <th>类型</th>
                <th>原因</th>
                <th>地点</th>
                <th>信息修改</th>
            </tr>
        </thead>
        <tbody>
            <%
            // 获取当前页（默认第一页）
            int currentPage = 1;
            int pageSize = 8;  // 每页显示n条记录
            String pageParam = request.getParameter("page");//至今为止不知道在哪设的
            String id = (String)session.getAttribute("sg");	//sg工号作用不大
            if (pageParam != null && !pageParam.isEmpty()) {
                currentPage = Integer.parseInt(pageParam);
            }
            
            WeiGuiDao dao = new WeiGuiDao();
            String build = (String)session.getAttribute("sgbuild");
                // 获取总记录数
                int totalUsers = dao.getSGCount(build);
                // 计算总页数
                int totalPages = (int) Math.ceil((double) totalUsers / pageSize);
                // 获取当前页的数据
                List<WeiGui> wgs = dao.getWGSGPage(build,currentPage, pageSize);
                for (WeiGui wg : wgs) {
            %>
            <tr>
                <td><%= wg.getId() %></td>
                <td><%= wg.getTime() %></td>
                <td><%= wg.getType() %></td>
                <td><%= wg.getBecause() %></td>
             	<td><%= wg.getAddress() %></td>
             	<td>
                   <button class="btn btn-green" onclick="window.location.href='WeiGuiSG_edit.jsp?id=<%= wg.getId() %>&time=<%= wg.getTime() %>&type=<%= wg.getType() %>'">
                				<i class="icon-eye"></i> 修改
                			</button>  
                     <button class="btn btn-green" onclick="window.location.href='WeiGuiSG_delete.jsp?id=<%= wg.getId() %>&time=<%= wg.getTime() %>&type=<%= wg.getType() %>'">
                				<i class="icon-eye"></i> 删除
                			</button> 
                </td>
            </tr>
            
            <%
                
                }
            %>
           
           	
            
        </tbody>
    </table>
     <!-- 分页显示 -->
    <div>
        <% if (currentPage > 1) { %>
            <a href="WeiGuiSG.jsp?page=<%= currentPage - 1 %>">上一页</a>
        <% } %>
        <span>页 <%= currentPage %> / <%= totalPages %></span>
        <% if (currentPage < totalPages) { %>
            <a href="WeiGuiSG.jsp?page=<%= currentPage + 1 %>">下一页</a>
        <% } %>
    </div>
    <!-- 按钮部分 -->
	<div style="text-align: center; margin-top: 20px;">
    	<button onclick="location.href='WeiGuiSG_add.jsp'" style="font-size: 15px; padding: 10px 20px; background-color: #1888df; color: white; border: none; border-radius: 5px;">
        添加违规信息记录</button>
	</div>
</div>

</body>
</html>